#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void solve(int n){
    if(n<10)cout<<n<<endl;
    else{
        int s=0;
        while(n){
            s+=n%10;
            n/=10;
        }
        solve(s);
    }
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    solve(n);

    return 0;
}